<?php
/*
 * 进云智能生成平台
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
 */

defined('BY_JYA') or exit('error');
global $_RQ,$_AR;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'award';
$return=array();
//查询当前粉丝是否关注当前公众号
$fans = cfc('core')->get_fans($_SESSION['openid']);
$fansinfo = pdo_get('core_fans',array('id'=>$fans['id'],'uniacid'=>$_SESSION['uniacid']));
$follow = $fansinfo['follow'];
set_html('title','获奖详情');
if($_RQ['op']=='award'){
	if($_RQ['id']){
		$id=intval($_RQ['id']);
	}
	if(!$id){
		exi('参数错误！','error');
	}
	 //查询对应活动的参数
	$item=pdo_get('jy_h5game_reply',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	//获取当前时间
	$time = time();
	//玩家是否被拉黑
	$shielding = pdo_getcolumn('jy_h5game_fans',array('fansId'=>$fansinfo['mid'],'uniacid'=>$_SESSION['uniacid']),'shielding');
	//是否关注公众号
	if($follow!= 1){
		//exi('请先关注公众号','error');
	}	
	if(!$item){
		exi('指定的活动不存在！','error');
	}
	if($shielding == 2){
	  	exi('抱歉，您被限制参与该活动','error');
	}
	if($item['status'] == 1){
		exi('活动尚未发布','error');
	}
	/*if($item['status'] == 3){
		exi('活动已结束','error');
	}
	*/
	//与开始时间、结束时间作比较
	if($time<$item['starttime']){
		$starttime=date('Y-m-d H:m:s',$item['starttime']);
		exi('活动还未开始，请于'.$starttime.'后参与','error');
	}
	/*if($time>strtotime($item['endtime'])){
		exi('活动已结束','error');
	}
	*/
	//获奖玩家 按奖品的等级顺序排名
	$awardlist = pdo_getall('jy_h5game_award',array('fansID'=>$_SESSION['uid'],'rid'=>$id,'uniacid'=>$_SESSION['uniacid']),'','','awardLevel asc');
	if($awardlist){
		foreach($awardlist as &$row){
			$row['headImg'] = pdo_getcolumn('jy_h5game_fans',array('rid'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid'],'fansID'=>$row['fansID']),'headImg');
		}
	}
	//该活动的获奖人数
	 $apnum = pdo_count('jy_h5game_award',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	 //当前玩家的奖品
	$award = pdo_get('jy_h5game_award',array('rid'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid'],'fansID'=>$_SESSION['uid']));
	
	//是否为红包模块
	if($item['fileName'] != 'hd_yaoyiyao' && $item['fileName'] != 'hd_hby' && $item['fileName'] != 'hd_fhb'){	
		  $show = 2;
	}else{
		  $show = 1;
	}
  //$return['html']='../'.ADDONS.'/jy_h5game/custom/templates/mobile/2048/index.html';
	$return['rank'] = array('action'=>'rankings','query'=>'rid='.$id,'plugin'=>'jy_h5game');
	$return['notice'] = array('action'=>'notice','query'=>'id='.$id,'plugin'=>'jy_h5game');
	//$return['info'] = array('action'=>'info','query'=>'id='.$id,'plugin'=>'jy_h5game');
	$return['item']=$item;
	$return['fansinfo']=$fansinfo;
	$return['apnum']=$apnum;
	$return['award']=$award;
	$return['myaward']=$awardlist;
	$return['show']=$show;
	$return['id']=$id;
	$return['htmls']=$this->template_url('myaward');
	exi($return);
}
if($_RQ['op']=='list'){
	if($_RQ['id']){
		$id=intval($_RQ['id']);
	}
	if(!$id){
		exi('参数错误！','error');
	}
	 //查询对应活动的参数
	$item=pdo_get('jy_h5game_reply',array('id'=>$id,'uniacid'=>$_SESSION['uniacid']));
	//获取当前时间
	$time = time();
	//玩家是否被拉黑
	$shielding = pdo_getcolumn('jy_h5game_fans',array('fansId'=>$fansinfo['mid'],'uniacid'=>$_SESSION['uniacid']),'shielding');
	//是否关注公众号
	if($follow!= 1){
		$return['follow']=$follow;
		//exi('请先关注公众号','error');
	}	
	if(!$item){
		exi('指定的活动不存在！','error');
	}
	if($shielding == 2){
	  	exi('抱歉，您被限制参与该活动','error');
	}
	if($item['status'] == 1){
		exi('活动尚未发布','error');
	}
	/*if($item['status'] == 3){
		exi('活动已结束','error');
	}
	*/
	//与开始时间、结束时间作比较
	if($time<$item['starttime']){
		$starttime=date('Y-m-d H:m:s',$item['starttime']);
		exi('活动还未开始，请于'.$starttime.'后参与','error');
	}
/*	if($time>strtotime($item['endtime'])){
	exi('活动已结束','error');
	}
	*/
	//获奖玩家 按奖品的等级顺序排名
	$awardlist = pdo_getall('jy_h5game_award',array('rid'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid']),'','','awardLevel asc');
	if($awardlist){
		foreach($awardlist as &$row){
			$row['headImg'] = pdo_getcolumn('jy_h5game_fans',array('rid'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid'],'fansID'=>$row['fansID']),'headImg');
		}
	}
	//exi($awardlist,'error');
	//该活动的获奖人数
	 $apnum = pdo_count('jy_h5game_award',array('rid'=>$id,'uniacid'=>$_SESSION['uniacid']));
	 //当前玩家的奖品
	$award = pdo_get('jy_h5game_award',array('rid'=>$_RQ['id'],'uniacid'=>$_SESSION['uniacid'],'fansID'=>$_SESSION['uid']));
	
	//是否为红包模块
	if($item['fileName'] != 'hd_yaoyiyao' && $item['fileName'] != 'hd_hby' && $item['fileName'] != 'hd_fhb'){		
		  $show = 2;
	}
	else{
		  $show = 1;
	}
  //$return['html']='../'.ADDONS.'/jy_h5game/custom/templates/mobile/2048/index.html';
	$return['rank'] = array('action'=>'rankings','query'=>'rid='.$id,'plugin'=>'jy_h5game');
	$return['notice'] = array('action'=>'notice','query'=>'id='.$id,'plugin'=>'jy_h5game');
	$return['info'] = array('action'=>'info','query'=>'id='.$id,'plugin'=>'jy_h5game');
	$return['myaward'] = array('action'=>'myaward','query'=>'id='.$id,'plugin'=>'jy_h5game');
	$return['item']=$item;
	$return['fansinfo']=$fansinfo;
	$return['apnum']=$apnum;
	$return['award']=$award;
	$return['awardlist']=$awardlist;
	$return['show']=$show;
	exi($return);
}
if($_RQ['op']=='post'){	
	if($_RQ['id']){
		$id=intval($_RQ['id']);
	}
	if(!$id){
		exi('参数错误！','error');
	}
	$postdata=get_postdata();
	$update=array(
		'awardstatus'=>1,
	);
	pdo_update('jy_h5game_award',$update,array('id'=>$id,'uniacid'=>$_SESSION['uniacid'],'fansID'=>$_SESSION['uid']));
	exi('提交成功','','jy_h5game/myaward//id='.$id);
}